/*
 * Animation.cpp
 *
 *  Created on: 10/11/2011
 *      Author: arleudo
 */

#include "lang/Animation.h"
#include "util/Timer.h"
#include "lang/World.h"

using namespace util;

namespace lang
{
	//--------------------------------------------------------------------------------
	Animation::Animation( std::vector<sf::Image> vetor, float _frequency )
	{
		imgs = vetor;
		totalFrames = vetor.size();
		frequency = _frequency;
	}
	//--------------------------------------------------------------------------------
	Animation::~Animation()
	{
	}
	//--------------------------------------------------------------------------------
	void Animation::addImageAtIndex( sf::Image *img, int indice )
	{
		//TODO: implements
	}
	//--------------------------------------------------------------------------------
	void Animation::addImageFront( sf::Image *img )
	{
		//TODO: implements
	}
	//--------------------------------------------------------------------------------
	void Animation::addImageBack( sf::Image *img )
	{
		//TODO: implements
	}
	//--------------------------------------------------------------------------------
	const sf::Image& Animation::run( void )
	{
		if ( currentFrame >= totalFrames - 1 ) currentFrame = 0;

		if ( timer.getTime() >= frequency )
		{
			currentFrame++;
			timer.reset();
		}
		return imgs.at( currentFrame );
	}
	//--------------------------------------------------------------------------------
	const sf::Image& Animation::slowMotion( const Object & target, int multipler )
	{
		if ( currentFrame >= totalFrames - 1 ) currentFrame = 0;

		if ( timer.getTime() >= frequency * multipler )
		{
			currentFrame++;
			timer.reset();
		}
		return imgs.at( currentFrame );
	}

} // namespace lang
